using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Peradigm.Framework.UI.Web;
using Peradigm.Framework.Domain.Security;

using Liberty.Application;
using Liberty.Application.ApplicationManagement;
using Liberty.Application.GrantManagement;
using Liberty.Application.ServiceMemberManagement;
using Liberty.Domain;
using Liberty.Domain.ApplicationManagement;
using Liberty.Domain.GrantManagement;
using Liberty.Domain.ServiceMemberManagement;
using Liberty.UI;
using Liberty.UI.GrantManagement.Controls;

namespace Liberty.UI.GrantManagement
{
    public partial class GrantListView : ThemedPage
    {
        #region Constants
        private const string
            PAGE_SERVICE_MEMBER_VIEW = "../ServiceMemberManagement/ServiceMemberView.aspx",
            PAGE_FIND_SERVICE_MEMBER = "../ServiceMemberManagement/ServiceMemberSearchView.aspx",
            PAGE_REMINDER_LIST_VIEW = "../ApprovalManagement/ReminderListView.aspx",
            PAGE_RECIPIENT_VIEW = "",
            PAGE_GRANT_VIEW ="../GrantManagement/GrantView.aspx";
        #endregion

        #region Event Handlers
        protected void Page_Load( object sender, EventArgs e )
        {
            if( !this.IsPostBack )
            {
                GrantController controller = new GrantController();
                UserVariable user = new UserVariable();
                List<Grant> grants = controller.GrantsFor( user.User );

                ucGrantListView.Model = grants;
            }

            this.ucGrantListView.ServiceMemberSelectedListeners += new ServiceMemberSelectedEventHandler( this.OnServiceMemberSelected );
            this.ucGrantListView.GrantSelectedListeners += new GrantSelectedEventHandler(this.OnGrantSelected);
            this.ucGrantListView.RecipientSelectedListeners += new RecipientSelectedEventHandler( this.OnRecipientSelected );
        }
        protected void btnAddGrant_Click( object sender, ImageClickEventArgs e )
        {
            this.Response.Redirect( PAGE_FIND_SERVICE_MEMBER );
        }
        protected void btnServiceMembers_Click( object sender, ImageClickEventArgs e )
        {
            this.Response.Redirect( PAGE_FIND_SERVICE_MEMBER );
        }
        protected void btnReminders_Click( object sender, ImageClickEventArgs e )
        {
            this.Response.Redirect( PAGE_REMINDER_LIST_VIEW );
        }
        #endregion

        #region Private Methods
        #endregion

        #region Properties
        #endregion

        #region Methods
        protected override void UpdateView()
        {
            base.UpdateView();
            ( (Main)this.Master ).HideGrantListAction();
        }
        #endregion

        #region Private Methods
        protected void OnServiceMemberSelected( ServiceMember serviceMember )
        {
            ServiceMemberVariable serviceMemberVariable = new ServiceMemberVariable();
            serviceMemberVariable.ServiceMember = serviceMember;

            this.Response.Redirect( PAGE_SERVICE_MEMBER_VIEW );
        }

        protected void OnGrantSelected(Grant grant)
        {
            GrantVariable grantVariable = new GrantVariable();

            grantVariable.Grant = grant;

            this.Response.Redirect(PAGE_GRANT_VIEW);
        }

        protected void OnRecipientSelected( Applicant recipient )
        {
            #warning save in session and redirect to Recipientview
            //this.Response.Redirect( PAGE_RECIPIENT_VIEW );
        }
        #endregion

        #region Private Properties
        #endregion

        #region Construction and Finalization

        #endregion

        #region Data Elements
        #endregion
        
}
}
